import { _decorator, Component, Node, game, director, Director, resources, Prefab } from 'cc';
const { ccclass, property } = _decorator;
import { BundleManager } from './bundle_Manager';
import { ResManager } from './res_Manager';


@ccclass('SceneManager')
export class SceneManager {
    private static _instance: SceneManager;
    public static get instance () {
        if (this._instance) {
            return this._instance;
        }

        this._instance = new SceneManager();
        return this._instance;
    }


    private _allInterludePrefab: any = {};

    /**
     * 初始化加载过场动画等
     */
    public init () {
        this.initAllInterludePrefab();
    }



    /**
     * 预加载并获取进度
     * @param senceName 
     * @param onProgress 
     * @param onLoaded 
     */
    public async preloadScene (senceName: string, onProgress: Director.OnLoadSceneProgress, onLoaded: Director.OnSceneLoaded) {
        director.preloadScene(senceName, onProgress, onLoaded);
    }


    /**
     * 预加载
     * @param senceName 
     * @param onLoaded 
     */
    public async nomorlPreloadScene (senceName: string, onLoaded: Director.OnSceneLoaded) {
        director.preloadScene(senceName, () => { }, onLoaded);
    }

    /**
     * 
     * @param name 
     */
    public getInterlude (name: string) {
        return this._allInterludePrefab[name];
    }

    /**
     * 初始化所以过度动画场景
     */
    public async initAllInterludePrefab () {
        const interludes = await ResManager.instance.loadBundleDirResByUrlOrName(`prefab/ui/interlude`, `resources`, Prefab) as Array<Prefab>;

        interludes.forEach(element => {
            this._allInterludePrefab[element.name] = element;
        });

    }

}

